#!/usr/bin/env python
import httplib
import solar
from config import config

def push(data):
    conn = httplib.HTTPConnection(config['host'])
    query = "/submit?system=%s&watts=%d&kwhToday=%2.2f&kwhLifetime=%f" \
      % (config['system'], data[0], data[1], data[2])
    conn.request("GET", query)
    return query
    
def pushnow():
  reader = solar.SolarReader()
  data = reader.getEnergy()
  # wierd data leaking through, retry
  if data[1] > 25:
    data = reader.getEnergy()
  return push(data)

if __name__ == "__main__":
  pushnow()

